package com.jgame.secondarymarket.interfaces.assembler.product;

import cn.hutool.core.bean.BeanUtil;
import com.jgame.secondarymarket.domain.product.entity.Product;
import com.jgame.secondarymarket.domain.product.entity.ProductProperties;
import com.jgame.secondarymarket.interfaces.dto.product.ProductDTO;
import com.jgame.secondarymarket.interfaces.vo.product.ProductVO;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 商品领域对象与DTO、VO转换
 *
 * @title: ProductAssembler
 * @Author Wangsj
 * @Date: 2021/7/22
 */
@Slf4j
public class ProductAssembler {

    public static Product toProduct(ProductDTO productDTO) {
        Product product = new Product();
        BeanUtil.copyProperties(productDTO, product);
        product.setRate(0.0);
        return product;
    }

    public static ProductVO toProductVO(Product product, List<ProductProperties> properties) {
        ProductVO productVO = new ProductVO();
        BeanUtil.copyProperties(product, productVO);
        //商品属性转换
        productVO.setProperties(ProductPropertiesAssembler.toVO(properties));
        return productVO;
    }
}
